<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ page import="javax.servlet.http.HttpServletRequest" %>
<%@ page import="utility.UserSession" %>
<%@ page import= "java.sql.ResultSet" %>
<%@ page import= "java.util.Vector" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Game Play</title>
</head>
<body>
<div id="b"><p><a href="/QSS/view/UserHome.jsp"><font color=#4682B4>Home</font></a></p></div>
<div id="e">
<p><a href="/QSS/view/Logout.jsp"><font color=#4682B4>Logout</font></a></p></div>
<div id="c"><b>${Topic} Quiz</b></div><br><br>
<%
// System.out.println(request.getSession().getAttribute("userID"));
// System.out.println((Integer)request.getSession().getAttribute("QNum"));
if((Integer)request.getSession().getAttribute("QNum")>10)
{
	RequestDispatcher RequestDispatcherObj =request.getRequestDispatcher("GameScore.jsp");
    RequestDispatcherObj.forward(request, response);
}
else
{

String Topic = (String)request.getSession().getAttribute("Topic");
String SubTopic=(String)request.getSession().getAttribute("SubTopic");
String ExactTopic=(String)request.getSession().getAttribute("ExactTopic");
ResultSet result = UserSession.getQuestion(Topic, SubTopic, ExactTopic); 

if(result!=null)
{
	result.beforeFirst();
	for(int i=0;i<(Integer)request.getSession().getAttribute("QNum")-1;i++)
	{
		result.next();
	}
	if(result.next())
	
	{
				 //System.out.println("ResultSet not Null");
	             int questionID = result.getInt("QuestionID");
	              Vector questions = (Vector)request.getSession().getAttribute("QList");
	             if(questions.contains(questionID))
	             {
	            	 
	             }
	             else
	             {
				 String question = result.getString("Question");
				 String optionA = result.getString("optionA");
				 String optionB = result.getString("optionB");
				 String optionC = result.getString("optionC");
				 String optionD = result.getString("optionD");
				 request.getSession().setAttribute("answer", result.getString("Answer"));
				 questions.add(questionID);
%> 

<div id="g">${QNum}.&nbsp;<%=question %><br><br>

<form method="post" action="AnswerFeedback.jsp">
&nbsp;<input type="radio" name="userResponse" value="A" ><%=optionA%><br><br>
&nbsp;<input type="radio" name="userResponse" value="B" ><%=optionB%><br><br>
&nbsp;<input type="radio" name="userResponse" value="C" ><%=optionC%><br><br>
&nbsp;<input type="radio" name="userResponse" value="D" ><%=optionD%><br><br>
<!-- <input type="submit" value = "Submit" onClick = "window.location = 'AnswerFeedback.jsp'"> -->
<input type="submit" value = "Submit" >
</form>
</div>
			 
<%
	             }
      }
	
	else
	{
        System.out.println("Sorry no questions in DB left");
    }
	}
}
// else
// {
%>
<!--     <div id="d"> -->
<!--     Oops... seems Database seems to be out of questions for this topic. Please click the button to go back to Game Home to continue with some other game. -->

<!--     <input type="button" value = "Quiz Home" onClick = "window.location = 'QuizHome.jsp'" style = "height:100px; width:150px" ><br><br> -->
<!--     </div> -->
<%--     <%} %> --%>
</body>
</html>